{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8eb89b65",
   "metadata": {},
   "source": [
    "# 课程内容\n",
    "* 常用模块\n",
    "* for 循环\n",
    "* for 循环 配合内置函数 range（）的使用\n",
    "* jupyter notebook 安装插件\n",
    "## 常用模块\n",
    "* datetime 模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6ff648a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用模块\n",
    "import datetime\n",
    "# datetime.(按TAp键查询)\n",
    "# help(datetime)\n",
    "\n",
    "# 我们可以使用moudle_name.Tap键来查看该模块的所有方法，但不能查看所有方法的细则及使用场景，help 可以帮助我们来做这件事"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c7012259",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.date(2021, 11, 15)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# datetime 里面的 date 方法\n",
    "datetime.date.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3868d2bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# datetime 里面的 date 方法 取出年月日\n",
    "datetime.date.today().day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e09d02f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "06d1aa7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2021"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.date.today().year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2b73e5f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2021-11-15'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# datetime 中 isoformat 格式化年月日\n",
    "datetime.date.isoformat(datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc55a9a5",
   "metadata": {},
   "source": [
    "* time模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6625e491",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "87d4384d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=11, tm_mday=15, tm_hour=4, tm_min=7, tm_sec=20, tm_wday=0, tm_yday=319, tm_isdst=0)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 国际标准时间\n",
    "time.gmtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0fa0911a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=11, tm_mday=15, tm_hour=12, tm_min=7, tm_sec=31, tm_wday=0, tm_yday=319, tm_isdst=0)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 本地时间\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0f7be6a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'12:07'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.strftime(\"%H:%M\")\n",
    "## 中间符号可自定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "86703323",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2021-11-15'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用time 的strftime方法 找到 年月日 然后拼接在一起即可\n",
    "time.strftime(\"%Y-%m-%d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "de2a81cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'PM'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.strftime(\"%p\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7be67c44",
   "metadata": {},
   "source": [
    "* random模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "25b05a1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9b11bc20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02954443278590757"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# (0,1)的随机数\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "09945d95",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1—26的随机数\n",
    "random.randint(1,26)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f8fef17",
   "metadata": {},
   "source": [
    "* for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "89b1e268",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "# 课本例题\n",
    "from datetime import datetime\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute # datetime.today().minute 当前的时间的分钟\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2c1aa72",
   "metadata": {},
   "source": [
    "* for循环 配合 内置函数range（）的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c63f089e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xiaoming---20201\n",
      "xiaohong---20202\n",
      "lihua---20203\n"
     ]
    }
   ],
   "source": [
    "names = ['xiaoming','xiaohong','lihua']\n",
    "# enumerate 枚举 产生steps的位置索引值（index）\n",
    "# for i in names : 取到了names中的值（values）\n",
    "# for 遍历数据的重要操作\n",
    "for k,i in enumerate(names):\n",
    "    print(i+\"---\"+str(20200+k+1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7961466",
   "metadata": {},
   "source": [
    "* 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "24a1adee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "grade:1\n",
      "freshman!come on!\n"
     ]
    }
   ],
   "source": [
    "a = input(\"grade:\") #input是一个输入栏，输入下面其中代码就有相应的结果。\n",
    "if a == \"1\":\n",
    "    print(\"freshman!come on!\")\n",
    "elif a == \"2\":\n",
    "    condition = input(\"sophomore!keep it on!\")\n",
    "    if condition == \"3\":\n",
    "        print(\"junior!you look like tired~\")\n",
    "    else:\n",
    "        print(\"ok!I know what your mean\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4021de7a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
